/*
  注:以下的整型数最低位为bit0.
  随机给定一个32位无符号整型数randNum的值.
  将randNum的bit7-bit17中的值加17,其余位不受影响.
 */
#include <stdio.h>
#include <stdlib.h>
#include "../MyFunc/MyFunc.c" //包含自定义的函数
int main(void)
{
	unsigned int randNum, tmp1 = 0, tmp2 = 0;
//	printf("%d",RAND_MAX); RAND_MAX为32767，只有15位
	randNum = (rand() << 30) + (rand() << 20) +((rand() << 10)) + rand() ; //产生随机数的方法有多种，这里只是一个示例
//	randNum = randNum | (1<<31);
	printf("随机randNum的二进制数为:");
//	myFuncToBin(randNum);
	char str1[32] = "";
	myFuncToBin2(randNum, str1);
	printf("\n");
	for (int i = 31; i >= 0; i--)
	{
		if (str1[i] == '\0')
			putchar('0');
		else
			putchar(str1[i]);
	}
	
	//0x7FF: 011111111111（共11个1，即17-7+1）, 将bit7-bit17之外的bit置为0
	tmp1 = randNum & (0x7FF << 7);
	tmp1 >>= 7;                  //取出bit7-bit17
	tmp1 += 17;                  //+17
	tmp2 = randNum & (~(0x7FF << 7)); // bit7-bit17清零
	tmp2 = tmp2 | (tmp1 << 7);
	printf("\n加17后所得二进制数为:");
//	myFuncToBin(tmp2);
	char str6[32] = "";
	myFuncToBin2(tmp2, str6);
	printf("\n");
	for (int i = 31; i >= 0; i--)
	{
		if (str6[i] == '\0')
			putchar('0');
		else
			putchar(str6[i]);
	}
}
